<template>
	<view class="pt-45 plr-30 bg white min100">


		<view class="head pl-30 pt-30 radius-20" style="background: #fff;">
			<view class="size-30 white">充值金额</view>


			<u-field label-width="0" :border-bottom="false" v-model="account" @input="changeReal" placeholder="输入充值金额"
				type="number" />
			</u-field>
		</view>
		<view class="pt-30 pb-30 size-32 white">选择充值方式</view>
		<view class="radius-20 pt-40 pb-40" style="background: #fff;">
			<view @click="selectPay(item.type)" class="flex pl-20 pr-20" v-for="(item,index) in payList" :key="index"
				:class="{'mt-50':index > 0}">
				<view class="flex1 flex-middle" @click="selectbank(item.type)">
					<image :src="item.iamge" style="width: 48rpx;height: 48rpx;" mode=""></image>
					<text class="size-28 white ml-20">{{ item.name }}</text>
					<image src="/static/login-more.png" mode="" style="width: 26rpx;height: 26rpx;margin-left: 20rpx;"
						v-if="item.type == 3"></image>
				</view>
				<image src="/static/select-pink.png" mode="" style="width: 32rpx;height: 32rpx;"
					v-if="payIndex == item.type"></image>
				<image src="/static/selects.png" mode="" style="width: 32rpx;height: 32rpx;" v-else></image>
			</view>
		</view>




		<view class="mt-100 mlr-30">
			<button class="default-button" @click="quit">充值</button>
		</view>
	</view>
</template>

<script>
	// #ifdef APP-PLUS
	const module = uni.requireNativePlugin('SandPayTypeModule')
	// #endif

	import tab from "../../components/tab.vue";
	import {
		upload
	} from "../../common/common.js";
	import {baseUrl} from '../../common/http.js';
	export default {
		components: {
			tab,
		},
		data() {
			return {
				realtyMoney: 0, //实际
				account: "",
				name: "",
				image: "",
				current: 0,
				walletAccount: 0,
				payList: [
					// {
					// 	name:'微信充值',
					// 	type:1,
					// 	iamge:'/static/weixin.png'
					// },
					// #ifdef H5
					// {
					// 	name: '汇付快捷',
					// 	type: 5,
					// 	iamge: '/static/zhifubao.png'
					// },
					// #endif
					// #ifdef APP-PLUS
					// {
					// 	name: '汇付快捷',
					// 	type: 4,
					// 	iamge: '/static/zhifubao.png'
					// },
					// #endif
					// #ifdef H5
					{
						name:'杉德',
						type:7,
						iamge:'/static/sahnde.png'
					},
					// #endif
					// #ifdef APP-PLUS
					{
						name:'杉德',
						type:8,
						iamge:'/static/sahnde.png'
					},
					// #endif
					// {
					// 	name:'银行卡 去选择',
					// 	type:3,
					// 	iamge:'/static/yinhangka.png'
					// }
				],
				// #ifdef H5
				payIndex: 7, //
				// #endif
				// #ifdef APP-PLUS
				payIndex: 8, //
				// #endif
				bankMessage: {}, //
			};
		},
		onShow() {

			if (uni.getStorageSync('bank')) {
				this.bankMessage = JSON.parse(uni.getStorageSync('bank'))

				this.payList[2].name = JSON.parse(uni.getStorageSync('bank')).bank_name + '(' + this.bankMessage.number
					.substring(this.bankMessage.number.length - 4, this.bankMessage.number.length) + ')'
			}
		},
		methods: {
			selectbank(type) {
				if (type == 3) {
					uni.navigateTo({
						url: '/pages/my/bindBank?type=1'
					})
				}
			},
			selectPay(type) {
				this.payIndex = type
			},
			// 展示实际到账
			changeReal(e) {
				let account = e;
			},
			change(e) {
				this.current = e;
			},
			quit() {

				if (this.account == "") {
					uni.showToast({
						title: "请输入充值金额!",
						icon: "none",
					});
					return;
				}
				if (this.payIndex == 7 || this.payIndex == 8) {
					uni.request({
						url: this.$url + 'api/pays/chongZhi', //仅为示例，并非真实接口地址。
						data: {
							price: this.account,
							pay_type: this.payIndex,
							tokens: uni.getStorageSync('token') || ''
						},
						success: (res) => {
							if (res.data.code == 1) {
								if (this.payIndex == 7) {
									// #ifdef H5
									location.href = res.data.data
									// #endif
								} else if (this.payIndex == 8) {
									module.cashierPayMulti(res.data.data, (res) => {
										console.log(res);
									})
								}
					
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								})
							}
						}
					});
				} else {
					uni.request({
						url: this.$url + 'api/zhi/zhifu', //仅为示例，并非真实接口地址。
						data: {
							price: this.account,
							pay_type: this.payIndex,
							tokens: uni.getStorageSync('token') || ''
						},
						success: (res) => {
							if (res.data.code == 1) {
								if (this.payIndex == 4) {
									uni.request({
										url: baseUrl + 'pay/AdapayDemo/index.php', //仅为示例，并非真实接口地址。
										data: {
											money: this.account,
											order_no: res.data.data.order_num
										},
										success: (res) => {
											if (res.data.status == 'succeeded') {
												plus.runtime.openURL(res.data.expend.pay_info)
											}
										}
									});
								} else if (this.payIndex == 5) {
									// #ifdef H5
									uni.request({
										url: baseUrl + 'pay/AdapayDemo/index.php', //仅为示例，并非真实接口地址。
										data: {
											money: this.account,
											order_no: res.data.data.order_num
										},
										success: (res) => {
											location.href = res.data.expend.pay_info
										}
									});
									// location.href = `https://huandao.ysxcs.cn/pay/AdapayDemo/index.php?money=${this.account}&order_no=${res.data.data.order_num}`
									// #endif
								} else if (this.payIndex == 7) {
									// #ifdef H5
									location.href = this.$url + 'index/index/pay?order_num=' + res.data.data.order_num
									// location.href = res.data.data
									// #endif
									// #ifdef APP-PLUS
									if (plus.os.name.toLowerCase() == 'ios') {
										plus.runtime.openURL(res.data.data)
									} else {
										uni.setStorageSync('payUrl', res.data.data)
										uni.navigateTo({
											url: '/pages/pay/web'
										})
									}
									// #endif
								} else if (this.payIndex == 8) {
									module.cashierPayMulti(res.data.data, (res) => {
										console.log(res);
									})
								}
					
							} else {
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								})
								// uni.removeStorageSync('token')
								// uni.reLaunch({
								// 	url: '/pages/login/index',
								// })
							}
						}
					});
				}
				
			}
		},
	};
</script>

<style lang="less" scoped>
	page{
	background: #f5f5f5;
}
.white {
  color: #3c3c3c;
}
.gold {
  color: #9c8b66;
}
	.upImg {
		width: 120rpx;
		height: 120rpx;
		margin-left: 30rpx;
	}

	.tips {
		color: #efe0c0;
	}

	.drawBtn {
		position: absolute;
		z-index: 10;
		bottom: 200rpx;
		left: 50%;
		transform: translateX(-50%);
	}

	/deep/ .u-field {
		color: #3c3c3c !important;
		font-size: 26rpx;
		padding: 30rpx 0 !important;
	}

	.default-button {
		color: #fff;
		font-size: 30rpx;
		height: 88rpx !important;
		line-height: 88rpx !important;
		background: linear-gradient(90deg, #EEA634, #DE2D32);
		border-radius: 44rpx;

		&::after {
			border: none;
		}
	}
</style>
